package com.hongruan.action.Report;

import java.util.List;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.hongruan.action.BaseAction;
import com.hongruan.bean.DataIntegra;
import com.hongruan.model.ResultStatusModel;
import com.hongruan.service.ReportService;

@Controller("ReportAction")
@Scope("prototype")
public class ReportAction extends BaseAction {

	private static final long serialVersionUID = 1506081115343890364L;
	private static Logger logger = Logger.getLogger(ReportAction.class);
	private String startdate;
	private String stopdate;
	private String swjgUuid;
	private String menuUuid;
	private String superSwjgUuid;
	private String formId;
	
	
	@Resource
	private ReportService reportService;
	
	//按业务分税务机关对比
	public String getListBySwjg(){
		
		logger.info("reportListBySwjg() begin");
		
        JSONObject json = new JSONObject();
        ResultStatusModel result = new ResultStatusModel();
        
        try{
        	List list = this.reportService.getListBySwjg(menuUuid,swjgUuid,startdate,stopdate);
        	if(list.size() > 0){
        		json.put("list", list);
            	result.setSuccess(true);
        	}else{
        		result.setSuccess(false);
        	}
        }catch(Exception e){
        	e.printStackTrace();
        	result.setSuccess(false);
        }
        json.put("result", result);
        this.writeAjaxResult(json.toString());
		return null;
		
	}
	//按业务分时间段统计
	public String getListBySjd(){
		
		logger.info("reportListBySjd() begin");
		
        JSONObject json = new JSONObject();
        ResultStatusModel result = new ResultStatusModel();
        
        try{
        	List list = this.reportService.getListBySjd(swjgUuid,startdate,stopdate);
        	if(list.size() > 0){
        		json.put("list", list);
            	result.setSuccess(true);
        	}else{
        		result.setSuccess(false);
        	}
        }catch(Exception e){
        	e.printStackTrace();
        	result.setSuccess(false);
        }
        json.put("result", result);
        this.writeAjaxResult(json.toString());
		return null;
		
	}
	
	//按业务分税务人员统计
	public String getListByCzry(){
		
		logger.info("reportListByCzry() begin");
		
        JSONObject json = new JSONObject();
        ResultStatusModel result = new ResultStatusModel();
        
        try{
        	List list = this.reportService.getListByCzry(swjgUuid,startdate,stopdate);
        	if(list.size() > 0){
        		json.put("list", list);
            	result.setSuccess(true);
        	}else{
        		result.setSuccess(false);
        	}
        }catch(Exception e){
        	e.printStackTrace();
        	result.setSuccess(false);
        }
        json.put("result", result);
        this.writeAjaxResult(json.toString());
		return null;
	}
	
	//根据SuperSwjgUuid获得下属机关信息
	public String listSwjgBySuperId(){
		logger.info("listSwjgBySuperId() begin");
		
        JSONObject json = new JSONObject();
        ResultStatusModel result = new ResultStatusModel();
        
        try{
        	List list = this.reportService.listSwjgBySuperId(superSwjgUuid);
        	if(list.size() > 0){
        		json.put("list", list);
            	result.setSuccess(true);
            	if(list.size() > 1)
            		result.setResultMsg("more");
            	else
            		result.setResultMsg("only");
        	}else{
        		result.setSuccess(false);
        	}
        }catch(Exception e){
        	e.printStackTrace();
        	result.setSuccess(false);
        }
        json.put("result", result);
        this.writeAjaxResult(json.toString());
		return null;
	}
	
	public String getListMenuById(){
		logger.info("getListMenu() begin");
		
        JSONObject json = new JSONObject();
        ResultStatusModel result = new ResultStatusModel();
        
        try{
        	List list = this.reportService.getListMenuById(menuUuid);
        	if(list.size() > 0){
        		json.put("list", list);
            	result.setSuccess(true);
        	}else{
        		result.setSuccess(false);
        	}
        }catch(Exception e){
        	e.printStackTrace();
        	result.setSuccess(false);
        }
        json.put("result", result);
        this.writeAjaxResult(json.toString());
		return null;
	}
	
	//统计总数
	public String getTotal(){
		logger.info("getTotal() begin");
		
        JSONObject json = new JSONObject();
        ResultStatusModel result = new ResultStatusModel();
        
        try{
        	List list = this.reportService.getTotal(menuUuid,startdate,stopdate);
        	if(list.size() > 0){
        		json.put("list", list);
            	result.setSuccess(true);
        	}else{
        		result.setSuccess(false);
        	}
        }catch(Exception e){
        	e.printStackTrace();
        	result.setSuccess(false);
        }
        json.put("result", result);
        this.writeAjaxResult(json.toString());
		return null;
	}
	
	//列表明细
	public String getDetail(){
		logger.info("getDetail() begin");
		
        JSONObject json = new JSONObject();
        ResultStatusModel result = new ResultStatusModel();
        
        try{
        	List<DataIntegra> list = this.reportService.getDetail(menuUuid,swjgUuid,startdate,stopdate);
        	if(list.size() > 0){
        		json.put("list", list);
            	result.setSuccess(true);
        	}else{
        		result.setSuccess(false);
        	}
        }catch(Exception e){
        	e.printStackTrace();
        	result.setSuccess(false);
        }
        json.put("result", result);
        this.writeAjaxResult(json.toString());
		return null;
	}
	
	//获得需要的表单名称
	public String getFormById(){
		logger.info("getFormById() begin");
		
        JSONObject json = new JSONObject();
        ResultStatusModel result = new ResultStatusModel();
        
        try{
        	List<DataIntegra> list = this.reportService.getFormById(formId);
        	if(list.size() > 0){
        		json.put("list", list);
            	result.setSuccess(true);
        	}else{
        		result.setSuccess(false);
        	}
        }catch(Exception e){
        	e.printStackTrace();
        	result.setSuccess(false);
        }
        json.put("result", result);
        System.out.println(json.toString());
        this.writeAjaxResult(json.toString());
		return null;
	}
	
	
	public String getStartdate() {
		return startdate;
	}
	public void setStartdate(String startdate) {
		this.startdate = startdate;
	}
	public String getStopdate() {
		return stopdate;
	}
	public void setStopdate(String stopdate) {
		this.stopdate = stopdate;
	}
	public String getSwjgUuid() {
		return swjgUuid;
	}
	public void setSwjgUuid(String swjgUuid) {
		this.swjgUuid = swjgUuid;
	}
	public String getMenuUuid() {
		return menuUuid;
	}
	public void setMenuUuid(String menuUuid) {
		this.menuUuid = menuUuid;
	}
	public String getSuperSwjgUuid() {
		return superSwjgUuid;
	}
	public void setSuperSwjgUuid(String superSwjgUuid) {
		this.superSwjgUuid = superSwjgUuid;
	}
	public String getFormId() {
		return formId;
	}
	public void setFormId(String formId) {
		this.formId = formId;
	}

}
